﻿<%@ WebHandler Language="C#" Class="JQueryGridTestHandler" %>

using System;
using System.Web;
using ajayumi.Platform;
using System.Text;
using System.Collections.Generic;
using ajayumi.Platform.Web.Controls.DataGrid;

public class JQueryGridTestHandler : JQueryGridHandlerBase
{
    public override void Create()
    {
        base.Create();
    }

    public override string Read(int currentPage, int pageSize)
    {
        int recordCount = 100;
        int totalPages = 0;
        if (recordCount % pageSize == 0)
        {
            totalPages = recordCount / pageSize;
        }
        else
        {
            totalPages = recordCount / pageSize + 1;
        }

        PersonCollection persons = new PersonCollection();

        StringBuilder sb = new StringBuilder();
        sb.Append("{");
        sb.Append("\"page\":" + currentPage + ",");
        sb.Append("\"total\":" + totalPages + ",");
        sb.Append("\"records\":" + recordCount + ",");
        sb.Append("\"rows\":[");

        List<PersonInfo> lst = persons.GetList(currentPage, pageSize);
        foreach (PersonInfo item in lst)
        {
            sb.AppendFormat("{{\"id\":\"{0}\",", item.Id);
            sb.Append("\"cell\":[");
            sb.AppendFormat("\"{0}\", \"{1}\",\"{2}\",\"{3}\",\"{4}\"",
                item.Id, item.Code, item.Name, item.Birthday, item.Address);
            sb.Append("]");
            sb.Append("},");
        }

        sb.Remove(sb.Length - 1, 1);
        sb.Append("]");
        sb.Append("}");

        return sb.ToString();
    }

    public override void Update()
    {
        base.Update();
    }

    public override void Delete(HttpContext context)
    {
        string ids = context.Request.Form["Id"].ToString();
        base.Delete(context);
    }

}